<template>
  <div id="ProductionAndMarketing" style="width: 100%; height: 80vh;padding: 10px"></div>
</template>

<script>
import * as echarts from "echarts";

export default {
  name: "ProductionAndMarketing",
  props:["ProductionAndMarketingData"],
  data() {
    return {
      data: this.ProductionAndMarketingData,
      loadStatus:0
    };
  },
  created() {
    // console.log(this.ProductionAndMarketingData)
  },
  mounted() {
    this.LeagueJS.getCarbonFactoryHistory(info=>{
      let child=[[],[],[],[]]
      info.map((i,j)=>{
        child[0].push(i.createToken)
        child[1].push(i.destoryToken)
        child[2].push(i.buyToken)
        child[3].push(j)
        j++
      })
      this.data = child
    })
    // this.renderEcharts();
  },
  watch:{
    "data":function (){
      console.log()
      this.renderEcharts();
    }
  },
  methods:{
    renderEcharts() {
      if (!document.getElementById("ProductionAndMarketing")) {
        return;
      }
      const chartDom = document.getElementById("ProductionAndMarketing");
      const myChart = echarts.init(chartDom);
      let option;

      option = {
        title: {
          text: '产销图'
        },
        legend: {
          data: ['总生产', '总销毁', '总购买']
        },
        tooltip: {
          trigger: 'axis',
          showContent: true
        },
        xAxis: {
          type: 'category',
          data: this.data[3]
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name:'总生产',
            data: this.data[0],
            type: 'line',
            smooth: true
          },
          {
            name:'总销毁',
            data: this.data[1],
            type: 'line',
            smooth: true
          }
          ,
          {
            name:'总购买',
            data: this.data[2],
            type: 'line',
            smooth: true
          }
        ]
      };

      option && myChart.setOption(option);
    },
  }
}
</script>

<style scoped>

</style>
